<template>
    <div class="newsinfo-container">
        <h3 class="title">{{newinfo.title}}</h3>
        <p class="subtitle">
            <span>发表时间:{{newinfo.add_time | dateFormat}}</span>
            <span>点击：{{newinfo.click}}次</span>
        </p>
        <div class="content" v-html="newinfo.content"></div>

         <!-- 评论子组件区域 -->
         <comment-box :id="this.id"></comment-box>
    </div>
</template>

<script>
import comment from "../subcomponents/comment.vue"
export default {
    data(){
        return {
            id:this.$route.params.id,
            newinfo:{}
        }
    },
    created() {
        this.getNewInfo();
    },
    methods:{
        getNewInfo(){
            this.$ajax.get("/api/getnew/"+this.id)
            .then((result)=>{
                console.log(result)
                if(result.data.status === 0){
                    this.newinfo = result.data.message[0]
                }else{
                    this.MintUI.Toast("获取数据失败");
                }
            })
            .catch((error) => {
                  this.MintUI.Toast(error);
            })
        }
    },
    components:{
       "comment-box": comment
    }
}
</script>

<style lang="less" scoped>
    .newsinfo-container{
        padding: 0 4px;
        .title{
            font-size: 18px;
            text-align: center;
            margin: 15px;
            color: red;
        }
        .subtitle{
            font-size: 13px;
            color: #226aff;
            display: flex;
            justify-content: space-between;
        }
        .content{
            /deep/ img{
                width: 100%;
            }
            //使用v-html创建的标签不会受被scoped的影响
            //子组件创建的标签不会被scoped影响
            // 所有需要使用 deep 深度作用选择器
        }
    }
</style>

